<template>
    <div class="goods-evaluate-image">
      <div class="list">
        <a
          href="javascript:;"
          :class="{active:currImage===url}"
          @click="handlePictureCardPreview(global.FILE_DOMAIN+url)"
          v-for="url in pictures"
          :key="url"
        >
          <img :src="global.FILE_DOMAIN+url" alt="">
        </a>
      </div>

      <!-- 图片预览 -->
      <el-dialog v-model="previewDialogVisible" width="50%" style="text-align: center;">
        <img style="width: 50%;" :src="previewDialogImageUrl" alt="">
      </el-dialog>
    </div>
  </template>
<script setup>
import { ref, inject } from 'vue'

// 获取全局对象
const global = inject('global')

defineProps({
    pictures: {
        type: Array,
        default: []
    }
})
    
const currImage = ref(null)

// 处理显示图片
const previewDialogImageUrl = ref('')
const previewDialogVisible = ref(false)
const handlePictureCardPreview = (url) => {
    previewDialogImageUrl.value = url;
    previewDialogVisible.value = true;
}
</script>
  
<style scoped lang="scss">
.goods-evaluate-image {
  .list {
    display: flex;
    flex-wrap: wrap;
    margin-top: 10px;
    a {
      display: block;
      width: 120px;
      height: 120px;
      border:1px solid #e4e4e4;
      margin-right: 20px;
      img {
        width: 100%;
        height: 100%;
        object-fit: contain;
      }
      &.active {
        border-color: $main-color;
      }
    }
  }
  .preview {
    width: 480px;
    height: 480px;
    border: 1px solid #e4e4e4;
    background: #f8f8f8;
    margin-bottom: 20px;
    position: relative;
    img {
        width: 100%;
        height: 100%;
        object-fit: contain;
    }
    i {
      position: absolute;
      right: 0;
      top: 0;
      width: 30px;
      height: 30px;
      background: rgba(0,0,0,0.2);
      color: #fff;
      text-align: center;
      line-height: 30px;
    }
  }
}
</style>